package secondriver.heathfood.bean;

import android.content.ContentValues;
import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;
import java.util.List;

/**
 * Author : secondriver
 */
public class FoodDetail {

    public static final FoodDetail Null = new FoodDetail();

    private long id;//	long	ID编码
    private String keywords;//	string	关键词
    private String name;//	string	名称
    private String description;//	string	简介
    private String img;//	string	图片
    private String message;//	string	内容
    private String food;//	string	相关食物
    private int count;//	int	访问数
    private int rcount;//	int	评论数
    private int fcount;//	int	收藏数
    private String images;//	String;//	多图，中间由 ， 隔开

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getFood() {
        return food;
    }

    public void setFood(String food) {
        this.food = food;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getRcount() {
        return rcount;
    }

    public void setRcount(int rcount) {
        this.rcount = rcount;
    }

    public int getFcount() {
        return fcount;
    }

    public void setFcount(int fcount) {
        this.fcount = fcount;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }

    @Override
    public String toString() {
        return "FoodDetail{" +
                "id=" + id +
                ", keywords='" + keywords + '\'' +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", img='" + img + '\'' +
                ", message='" + message + '\'' +
                ", food='" + food + '\'' +
                ", count=" + count +
                ", rcount=" + rcount +
                ", fcount=" + fcount +
                ", images='" + images + '\'' +
                '}';
    }

    public static class MetaInfo {

        public static final String TABLE_NAME = "t_food_detail";

        public static String[] getInitScript() {
            String drop = new StringBuilder("DROP TABLE IF EXISTS ").append(TABLE_NAME).toString();
            String create = new StringBuilder("CREATE TABLE IF NOT EXISTS ")
                    .append(TABLE_NAME)
                    .append("( ")
                    .append("_id INTEGER PRIMARY KEY AUTOINCREMENT, ")
                    .append("f_id INTEGER UNIQUE, ")
                    .append("f_keywords VARCHAR, ")
                    .append("f_name VARCHAR, ")
                    .append("f_description VARCHAR, ")
                    .append("f_img VARCHAR, ")
                    .append("f_images VARCHAR, ")
                    .append("f_message VARCHAR, ")
                    .append("f_food INTEGER, ")
                    .append("f_count INTEGER, ")
                    .append("f_rcount INTEGER, ")
                    .append("f_fcount INTEGER")
                    .append(")")
                    .toString();
            return new String[]{drop, create};
        }

    }

    public static class FoodDetailBuilder implements Builder<FoodDetail> {

        @Override
        public FoodDetail builderToTarget(ContentValues cv) {
            FoodDetail foodDetail = new FoodDetail();
            foodDetail.setId(cv.getAsLong("f_id"));
            foodDetail.setKeywords(cv.getAsString("f_keywords"));
            foodDetail.setName(cv.getAsString("f_name"));
            foodDetail.setDescription(cv.getAsString("f_description"));
            foodDetail.setImg(cv.getAsString("f_img"));
            foodDetail.setImages(cv.getAsString("f_images"));
            foodDetail.setMessage(cv.getAsString("f_message"));
            foodDetail.setFood(cv.getAsString("f_food"));
            foodDetail.setCount(cv.getAsInteger("f_count"));
            foodDetail.setRcount(cv.getAsInteger("f_rcount"));
            foodDetail.setFcount(cv.getAsInteger("f_fcount"));
            return foodDetail;
        }

        @Override
        public ContentValues builderToContentValues(FoodDetail o) {
            ContentValues cv = new ContentValues(12);
            cv.put("f_id", o.getId());
            cv.put("f_keywords", o.getKeywords());
            cv.put("f_name", o.getName());
            cv.put("f_description", o.getDescription());
            cv.put("f_img", o.getImg());
            cv.put("f_images", o.getImages());
            cv.put("f_message", o.getMessage());
            cv.put("f_food", o.getFood());
            cv.put("f_count", o.getCount());
            cv.put("f_rcount", o.getRcount());
            cv.put("f_fcount", o.getFcount());
            return cv;
        }
    }
}